<?php
class ZendX_Extjs_View_Helper_ExtComponent extends ZendX_Extjs_View_Helper_Base
{
	public function extComponent($componentType, array $config = array(), $varname=null)
	{
		$js = $this->js($componentType, $config, $varname);		
        $this->extjs->addOnLoad($js);
	}
	
	public static function js($componentType, array $config = array(), $varname=null)
	{
		$conf = Zend_Json::encode($config, false, array('enableJsonExprFinder' => true));
		
		$js = "";
		if (is_null($varname)) {
			$js = sprintf('Ext.create("%s",%s);', $componentType, $conf);
		}
		else {
			$js = sprintf('var %s = Ext.create("%s",%s);', $varname, $componentType, $conf);
		}
		return $js;
	}
}